<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="include :: head">page head</head>

<style>
	.alert .fa {font-size: 20px; float: right;}
</style>
<body class="text-center">

<div class="container d-flex h-100 p-3 mx-auto flex-column">
	<div th:replace="include :: top">header goes here.</div>
	
	<main role="main" class="inner cover mt-5 pt-5 index-main" id="app">
		<h1 class="cover-heading">Filecoin 钱包（开发网络版）</h1>
		<p class="lead m-4 text-left">Gamma Wallet 是一款 Filecoin 轻钱包，目前基于 Filecoin
			开发网络，由于开发网络目前钱包的功能尚未开发完成，目前仅实现了创建钱包，转账，和查看余额的功能。
			等官方钱包接口完善之后我们会同步更新。
		</p>
		<div class="text-center">
			<a href="javascript:void(0);" v-on:click="newAddress" class="btn btn-lg btn-primary">生成一个新的钱包地址</a>
		</div>
		
		<div class="card mt-4" v-show="show">
			<div class="card-body text-dark">
				<div class="alert alert-info text-left" role="alert">
					钱包地址： {{ address }}
				</div>
				<div class="alert alert-info text-left" role="alert">
					钱包私钥： {{ privateKey }}
					<i class="fa fa-eye" style="cursor: pointer" v-on:click="showPrivateKey" v-show="showEye"
					   title="显示秘钥"></i>
					<i class="fa fa-eye-slash" style="cursor: pointer" v-on:click="hidePrivateKey" v-show="!showEye"
					   title="隐藏秘钥"></i>
				</div>
				
				<div>
					<p class="text-danger">注意: 当前为开发网络，钱包私钥没有加密，请妥善保管.</p>
					<button type="button" class="btn btn-success mb-2 ml-2" v-on:click="downloadWallet">下载钱包文件</button>
				</div>
			</div>
		</div>
	
	</main>
	
	<div th:replace="include :: footer">footer goes here.</div>
</div>

<script>
	new Vue({
		el: "#app",
		data: {
			address: "",
			pkReplacement: "**************************************************************************",
			privateKey: "",
			_privateKey: "",
			walletPass: "",
			showEye: true,
			show: false
		},
		mounted: function() {
			this.privateKey = this.pkReplacement;
		},
		methods: {
			// 创建一个新钱包
			newAddress: function () {
				var that = this;
				var loading = messageLoading();
				setTimeout(function () {
					httpGet("/api/filecoin/newAddress", function
						(res) {
						messageOk("钱包创建成功.");
						loading.hide();
						var data = res.data;
						that.address = data.address;
						that._privateKey = data.privateKey;
						that.show = true;
					}, function (message) {
						loading.hide();
						messageError(message);
					});
				}, 1000);
			},
			
			// 下载钱包 keystore 文件
			downloadWallet: function () {
				location.href = "/wallet/download/"+this.address;
			},
			// 显示私钥
			showPrivateKey: function () {
				this.privateKey = this._privateKey;
				this.showEye = false;
			},
			hidePrivateKey: function () {
				
				this.privateKey = this.pkReplacement;
				this.showEye = true;
				
			}
		}
	});
</script>
</body>
</html>